# 嵌套函数
print('******函数嵌套******')
def outer():
    def inner():
        print('inner')
    print('outer')
    inner()

outer()

# 作用域
print('******作用域******')
x = 5
def f():
    global x
    x +=1
    print(x)

print(x)
f()

print('******First definition******')
def factorial(n):
    def recurse(n,product):
        if n == 1:
            print(product)
            return product
        else:
            return recurse(n-1,product*n)
    recurse(n,1)
factorial(3)
    
print('******Second definition******')
def factorial(n,product = 1):
    if n == 1:
        print(product)
        return product
    else:
        return factorial(n-1,product*n)

factorial(3)